<!-- 编辑弹窗 -->
<template>
    <ele-modal
      inner
      fullscreen
      :movable="false"
      :visible="visible"
      :close-on-click-modal="true"
      custom-class="ele-dialog-form"
      :title="isUpdate ? '预收款' : '预收款'"
      @update:visible="updateVisible"
    >
    <div class="ele-body">
      <el-card>
        <!-- 搜索表单 -->
        <prereviceitemListSearch @search="reload"  />
      </el-card>
      <el-card>
        <ele-pro-table ref="table"  row-key="id" :columns="warehouseItemColumns"  :datasource="datasource"  :need-page="true"  :cell-style="cellStyle" :height="tableHeight" :full-height="tableFullHeight">
          <template slot="outOrderNo" slot-scope="{ row }"  >
            <el-link  type="primary"   @click="clickbillNo(row)" >{{ row.outOrderNo }}</el-link>
          </template>

          <template slot="action" slot-scope="{ row }"  >
            <el-popconfirm class="ele-action" title="确定要作废吗？"  @confirm="remove(row)" >
              <el-link type="danger" slot="reference" :underline="false"  icon="el-icon-delete" >作废</el-link>
            </el-popconfirm>
          </template>
        </ele-pro-table>
      </el-card>
    </div>
    </ele-modal>
  </template>
  <script>

  //初始化对像
  import { removePageTab } from '@/utils/page-tab-util';
  import prereviceitemListSearch from '../components/prereviceitem-list-search.vue';
  import { QueryPrereviceitemPageList,DeletePrereviceitem } from '@/api/finance/prereviceitem';
  export default {
    name: 'PrereviceItemList',
    props: {
      // 弹窗是否打开
      visible: Boolean,
      // 修改回显的数据
      data: Object,
    },
    components:{prereviceitemListSearch},
    data() {
      return {
        // 表单数据
        form: {},
        fixedHeight:true,
        // 提交状态
        loading: false,
        // 是否是修改
        isUpdate: false,
        // 表格列配置
        warehouseItemColumns: [
          {columnKey: 'index', type: 'index', width: 50, align: 'center', showOverflowTooltip: true, fixed: 'left', label:'序号',},
          {prop: 'bankAccountDesc', label: '银行',showOverflowTooltip: true, align: 'center', sortable: 'bankAccountId'},
          {prop: 'preNum', label: '单号',showOverflowTooltip: true,sortable:'preNum', align: 'center',},
          {prop: 'customerName', label: '客户名称', showOverflowTooltip: true, align: 'center', sortable: 'customerName'},
          {prop: 'amount', label: '金额', showOverflowTooltip: true,sortable:'amount', align: 'center',},
          {prop: 'currencyDesc', label: '币种',showOverflowTooltip: true, align: 'center', sortable: 'currencyId'},
          {
            prop: 'reviceDate', label: '收款日期', showOverflowTooltip: true, align: 'center',sortable: 'reviceDate',
            formatter: (row, column, cellValue) => {return this.$util.toDateString(cellValue,"YYYY-MM-DD");}
          },
          {prop: 'outOrderNo', label: '出库单号', showOverflowTooltip: true,sortable:'outOrderNo',slot:'outOrderNo', align: 'center',},
          {prop: 'directionDesc', label: '方向', showOverflowTooltip: true,sortable:'direction', align: 'center',},
          {prop: 'operatorName', label: '经办人', showOverflowTooltip: true, align: 'center', sortable: 'operatorName'},
          {columnKey: 'action', label: '操作',align: 'center',slot:'action', resizable: false, hideInSetting: true, showOverflowTooltip: true}
        ],
      };
    },
    computed: {
        // 表格高度
        tableHeight() {
          var fh = this.fixedHeight ? 'calc(100vh - 350px)' : void 0;
          return fh;
        },
        // 表格全屏时高度
        tableFullHeight() {
          var fh =  this.fixedHeight ? 'calc(100vh - 250px)' : null;
          return fh;
        },
      },
    methods: {

      /* 表格数据源 */
      async datasource(params) {

        params.where.pageindex = params.page;
        params.where.pagesize = params.limit;

        //添加排序
        if(params.order.order == null || params.order.order == undefined){
          params.where.orderBys = [{ sort: "createDate", order: 1, }];
        }else{
          params.where.orderBys = [];
          params.where.orderBys.push({sort:params.sorter.column.sortable,order:params.order.order=='asc'?0:1});
        }

        if(!params.where.conditions) params.where.conditions = [];

        if(this.form.customerId){
          params.where.conditions.push({
            key:"customerId",
            operator: 0,
            value:  this.form.customerId,
          });
        }

        if(!params.where.conditions)params.where.conditions= [];
        params.where.conditions.push({ key:"deleted", operator: 0, value: 0, });

        let data = await QueryPrereviceitemPageList(params.where);

        return {
            list:data.items,
            count:data.totalrecords,
        };
      },

      /* 更新visible */
      updateVisible(value) {
        //更新父组件中的visible的值
        this.$emit('update:visible', value);
        //更新文件列表对像
      },

      /* 刷新表格 */
      reload(where) {
        if(this.$refs.table){
          this.$refs.table.reload({ where: where });
        }
      },

      //单击单号
      clickbillNo(row){
        removePageTab({ key: '/businesshandling/saleoutmanager' });
        this.$nextTick(() => {
          this.$router.push({path: '/businesshandling/saleoutmanager', query: { "orderNo": row.outOrderNo } });
        });
      },

      /* 删除 */
      remove(row) {
        const loading = this.$loading({ lock: true });
        DeletePrereviceitem(row.id)
          .then((msg) => {
            loading.close();
            this.$message.success(msg);
            this.reload();
          })
          .catch((e) => {
            loading.close();
            this.$message.error(e.message);
          });
      },

      /* 导出 */
      reportexcel(pams) {
        //初始化参数
        let params = {
          pagesize: 0,
          pageindex: 1,
          conditions: [],
          orderBys: [{ sort: "createDate", order: 1, }],
        };
        //加载进度条
        const loading = this.$loading({ lock: true });
        //重新请求查询
        this.$refs.table.doRequest(({ where }) => {
        if(where){
          params.orderBys = where.orderBys;
          params.pageindex = where.pageindex;
          params.conditions = where.conditions;
        }
        //查询数据
        QueryPrereviceitemPageList(params)
          .then((data) => {
            loading.close();
            this.$refs.ExportDialog.showEdits = true
            this.$refs.ExportDialog.checkList = this.exportList
            this.$refs.ExportDialog.titleName = "预收款明细列表"
            this.$refs.ExportDialog.dataList = data.items;
          })
          .catch((e) => {
            loading.close();
            this.$message.error(e.message);
          });
        });
      },

      /* 样式 */
      cellStyle(param){
        const { row, column, rowIndex, columnIndex } = param;
        if(columnIndex==4){
          return{
            color:''
          }
        }
      },
  },
    
    /* 监听visible属性变化 */
    watch: {
      visible(visible) {
        if (visible) {
          //赋值this.form
          this.form = this.data;
          this.isUpdate = true;

          this.reload();
        } 
      }
    }
  };
  </script>